<?php
header("content-type:text/html;charset=utf-8");
session_start();
date_default_timezone_set('PRC');
if(isset($_SESSION["u_user"])) {
    $name = $_SESSION["u_user"];
	include_once('classes/user/user.class.php');//admin.php 跟classes 是同级  所以不用../ ../就是上级目录
	include_once('classes/depart/depart.class.php');
	include_once('classes/addtime/time.class.php');
	include_once('classes/page.class.php');
	$user = new user();
	$depart = new depart();
	$date = date("n");
    $time = new time();
	if(isset($_POST['submit'])) {
		$department = $_POST['department'];
		$date = $_POST['month'];
		if($department!='all') {
		$num = 0;
        $depart_one = $depart->get_one_depart($department,'d_name');
		$user_depart = $user->get_all_user($where='d_id="'.$depart_one['d_id'].'"');
		for($i=0; $i<count($user_depart); $i++) {
			$number = $time->get_count_time('u_id="'.$user_depart[$i]['u_id'].'" AND del ="1" AND a_month="'.$date.'"');
			$num+=$number;
		}
		$page = new page($num);
		} else {
		    $num = 0;
	        $user_depart = $user->get_all_user();
            for($i=0; $i<count($user_depart); $i++) {
		        $number = $time->get_count_time('u_id="'.$user_depart[$i]['u_id'].'" AND del ="1" AND a_month="'.$date.'"');
                $num += $number;
		    }
		    $page = new page($num);
		}
    } else {
		$num = 0;
	    $user_depart = $user->get_all_user();
        for($i=0; $i<count($user_depart); $i++) {
		    $number = $time->get_count_time('u_id="'.$user_depart[$i]['u_id'].'" AND del ="1" AND a_month="'.$date.'"');
            $num += $number;
		}
		$page = new page($num-1);
	}
	if(isset($_POST['export'])) {
		echo '<script>location.href="export.php?month='.$_POST['month'].'&name='.$_POST['department'].'"</script>';
	}
	$dep = $depart->get_all_depart();
    
	

?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="caches/css/bootstrap.css">
        <link rel="stylesheet" href="caches/css/font-awesome.min.css">
        <link rel="stylesheet" href="caches/css/style.css">
        <link rel="stylesheet" href="caches/css/plugin.css">
        <link rel="stylesheet" href="caches/css/landing.css">

        <!--[if lt IE 9]>
        <script src="caches/js/ie/respond.min.js"></script>
        <script src="caches/js/ie/html5.js"></script>
        <![endif]-->
		<style>
			.bt {
			  display: inline-block;
			  padding: 10px 15px;
			  font-size: 12px;
			  cursor: pointer;
			  text-align: center;   
			  text-decoration: none;
			  outline: none;
			  color: #fff;
			  background-color: #4CAF50;
			  border: none;
			  border-radius: 15px;
			  box-shadow: 0 9px #999;
			}

			.bt:hover {background-color: #3e8e41}

			.bt:active {
			  background-color: #3e8e41;
			  box-shadow: 0 5px #666;
			  transform: translateY(4px);
			}
		</style>
    </head>
    <body>
    <!-- header -->
    <header id="header" class="navbar">
        <ul class="nav navbar-nav navbar-avatar pull-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <span class="hidden-sm-only"></span>
                    <span class="thumb-small avatar inline"><img src="caches/images/avatar.jpg" alt="" class="img-circle"></span>
                    <b class="caret hidden-sm-only"></b>
                </a>
                <ul class="dropdown-menu">
                    <li class="icon-gear"><span class="text"><a href="#">设置</a></span></li>
                    <li class="divider"></li>
                    <li class="icon-signout"><span class="text"><a href="quit.php">注销</a></span></li>
                </ul>
            </li>
        </ul>
        <a class="navbar-brand" href="#">管理</a>
        <button type="button" class="btn btn-link pull-left nav-toggle hidden-lg" data-toggle="class:slide-nav slide-nav-left" data-target="body">
            <i class="icon-reorder icon-xlarge text-default"></i>
        </button>
        <ul class="nav navbar-nav hidden-sm">
            <li class="dropdown shift" data-toggle="shift:appendTo" data-target=".nav-primary .nav">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-cog icon-xlarge visible-sm visible-sm-inline"></i>设置<b class="caret hidden-sm-only"></b></a>
                <ul class="dropdown-menu">
                    <li>
                        <a href="#" data-toggle="class:navbar-fixed" data-target='body'>
                            <span class="text-active">自动</span>
                            <span class="text">固定</span>
                        </a>
                    </li>
                    <li class="visible-lg">
                        <a href="#" data-toggle="class:nav-vertical" data-target="#nav">
                            <span class="text-active">垂直</span>
                            <span class="text">水平</span>
                        </a>
                    </li>
                    <li class="divider hidden-sm"></li>
                    <li class="dropdown-header">颜色</li>
                    <li>
                        <a href="#" data-toggle="class:bg bg-black" data-target='.navbar'>上：
                            <span class="text-active">白色</span>
                            <span class="text">黑色</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" data-toggle="class:bg-light" data-target='#nav'>左：
                            <span class="text-active">暗</span>
                            <span class="text">亮</span>
                        </a>
                    </li>
                </ul>
            </li>
        </ul>
    </header>
    <nav id="nav" class="nav-primary visible-lg nav-vertical">
        <ul class="nav" data-spy="affix" data-offset-top="50">
            <li class="dropdown-submenu">
                <a href="#"><i class="icon-group icon-xlarge"></i>部门</a>
                <ul class="dropdown-menu">
                    <li><a href="add_depart.php">新增</a></li>
                    <li><a href="department.php">编辑</a></li>
                </ul>
            </li>
            <li class="dropdown-submenu">
                <a href="#"><i class="icon-male icon-xlarge"></i>员工</a>
                <ul class="dropdown-menu">
                    <li><a href="add_user.php">新增</a></li>
                    <li><a href="users.php">编辑</a></li>
                </ul>
            </li>
            <li><a href="admin.php"><i class="icon-edit icon-xlarge"></i>加班信息</a></li>
            <li class="dropdown-submenu">
                <a href="#"><i class="icon-signout icon-xlarge"></i>其他</a>
                <ul class="dropdown-menu">
                    <li><a href="quit.php">注销</a></li>
                </ul>
            </li>
        </ul>
    </nav>


        <!-- 内容区域 -->
       <section id="content">
    <section class="main padder">
      <div class="clearfix">
        <h4><i class="icon-edit"></i>加班信息</h4>
      </div>
      <div class="row">
          <div class="panel">
            <div class="clearfix">
			<!--
				<div class="clearfix" align="right">
					<button type="button" class="btn btn-default" aria-label="Left Align">
					  <i class="glyphicon glyphicon-download-alt" aria-hidden="true"></i>
					  <a href="export.php?a_month='.$_POST['month'].'">导出
					  <input type="hidden" name="month"  value="<?php echo $date;?>">
					  <input type="hidden" name="department"  value="<?php echo $department;?>">
					  </a>
					</button>
				</div>-->
				<form class="form-horizontal" action="admin.php" method="post">
					<div class="form-group">
						<div class="col-sm-2">
                          <select class="form-control" id="department" name="department" type="text" placeholder="全部部门">
							  <option value="all" selected="selected">全部部门</option>
							  <?php 
							  $date = $_POST['month'];
							  for($i=0;$i<count($dep);$i++){?>
								    <option value="<?php echo $dep[$i]['d_name']?>"><?php echo $dep[$i]['d_name']?></option>
							  <?php }?>
                          </select>
						</div>
						<div class="col-sm-2">
						  <select class="form-control" name="month" type="month"  placeholder="<?php echo $date;echo date("n");?>">
							<option value="1" <?php if($date=='1') echo 'selected="selected"'?>>1</option>
							<option value="2" <?php if($date=='2') echo 'selected="selected"'?>>2</option>
							<option value="3" <?php if($date=='3') echo 'selected="selected"'?>>3</option>
							<option value="4" <?php if($date=='4') echo 'selected="selected"'?>>4</option>
							<option value="5" <?php if($date=='5') echo 'selected="selected"'?>>5</option>
							<option value="6" <?php if($date=='6') echo 'selected="selected"'?>>6</option>
							<option value="7" <?php if($date=='7') echo 'selected="selected"'?>>7</option>
							<option value="8" <?php if($date=='8') echo 'selected="selected"'?>>8</option>
							<option value="9" <?php if($date=='9') echo 'selected="selected"'?>>9</option>
							<option value="10" <?php if($date=='10') echo 'selected="selected"'?>>10</option>
							<option value="11" <?php if($date=='11') echo 'selected="selected"'?>>11</option>
							<option value="12" <?php if($date=='12') echo 'selected="selected"'?>>12</option>
                          </select>
						 </div>
						 <div class="col-sm-1">
							<button type="submit" name="submit"class="bt">查找</button>
						 </div>
						 <div class="col-sm-1" align="right">
							<button type="submit" name="export"class="bt" action="export.php">导出</button>
						 </div>
					</div>
				</form>
							
				<div  class="col-md-8" align="center" >
					<table  class="table table-striped table-condensed">
					<div  class="col-md-8" align="center" >
						<table  class="table table-striped table-condensed">
							<tr>
								<th>姓名</th>
								<th>部门</th>
								<th>项目</th>
								<th>日期</th>
								<th>月份</th>
								<th>天数</th>
							</tr>
							<?php 
							for($n=0; $n<count($user_depart); $n++)
							{
								$jb = $time->get_all_time($where=' u_id="'.$user_depart[$n]['u_id'].'"AND a_month="'.$date.'"',$limit=$page->limit);
								for($m=0;$m<count($jb);$m++) {
							?>
							<tr>
								<td><?php echo $user_depart[$n]['u_user']?></td>
								<td><?php $depthis = $depart->get_one_depart($user_depart[$n]['d_id'],'d_id');
										  echo $depthis['d_name'];
									?></td>
								<td><?php echo $jb[$m]['a_project'];?></td>
								<td><?php echo $jb[$m]['a_date'];?></td>
								<td><?php echo $jb[$m]['a_month']?></td>
								<td><?php echo $jb[$m]['a_day']?></td>
							</tr>
							<?php } }?>
						</table>
					<div  class="col-md-8" align="center" >
					<table  class="table table-striped table-condensed">
						<div  class="col-md-8" align="center" >
							<table><td colspan="6"><?php echo $page->fpage();?></td></table>
						</div>
					</table>
				</div>
			</div>
		</div>
	</div>
  </section>
  </section>
    <footer id="footer">
        <div class="text-center padder clearfix">
            <p>
                <small>&copy;山东舜网传媒股份有限公司</small><br><br>
            </p>
        </div>
    </footer>
    <!-- / footer -->
    <script src="caches/js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="caches/js/bootstrap.js"></script>
    <!-- app -->
    <script src="caches/js/app.js"></script>
    <script src="caches/js/app.plugin.js"></script>
    <script src="caches/js/app.data.js"></script>
    <!-- fuelux -->
    <script src="caches/js/fuelux/fuelux.js"></script>
    <!-- datepicker -->
    <script src="caches/js/datepicker/bootstrap-datepicker.js"></script>
    <!-- slider -->
    <script src="caches/js/slider/bootstrap-slider.js"></script>
    <!-- file input -->
    <script src="caches/js/file-input/bootstrap.file-input.js"></script>
    <!-- combodate -->
    <script src="caches/js/combodate/moment.min.js"></script>
    <script src="caches/js/combodate/combodate.js"></script>
    <!-- parsley -->
    <script src="caches/js/parsley/parsley.min.js"></script>
    </body>
    </html>
<?php 

}
else
{
	echo '<script>alert("请先登录");location.href="../work/login1.php";</script>';
}


?>